package com.gaogzhen.intro.state;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j(topic = "c.TestWaiting01")
public class TestWaiting01 {

    public static void main(String[] args) throws InterruptedException {
        Object obj = new Object();
        new Thread(() -> {
            log.debug("wait ...");
            synchronized (obj) {
                try {
                    obj.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                log.debug("t1 continue ... ");
            }

        }, "t1").start();
        new Thread(() -> {
            log.debug("wait ...");
            synchronized (obj) {
                try {
                    obj.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                log.debug("t2 continue ... ");
            }

        }, "t2").start();

        TimeUnit.SECONDS.sleep(1);
        log.debug("notifyAll ... ");
        synchronized (obj) {
            obj.notifyAll();
        }
    }
}
